//
//  String+extension.swift
//  TableViewSwift
//
//  Created by 郭颢源 on 2021/1/11.
//  Copyright © 2021 lisonglin. All rights reserved.
//

import Foundation
extension String{
    
    /// Base64 编码
    /// - Returns: 返回编码后的字符串
    func encodeBase64() -> String {
        if let data = self.data(using: .utf8) {
            return data.base64EncodedString()
        }
        return ""
    }
    
    /// Base64 解码
    /// - Returns: 返回解码后的字符串
    func decodeBase64() -> String {
        if let data = Data(base64Encoded: self){
            return String(data: data, encoding: .utf8) ?? ""
        }
        return ""
    }
}
